﻿using System;
using System.IO;
using System.Net;
using System.Text;
using log4net;

//[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Service
{
    public  class WebRequestService : IWebRequest
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Nullable));

        public string GetRequestByUrl(string Url,string type)
        {
            try
            {
                string Return = null;
                WebRequest wRequest = WebRequest.Create(Url);
                wRequest.Method = type;
                WebResponse wResponse = wRequest.GetResponse();
                log.InfoFormat("获取对InterNet资源的数据成功");
                Stream stream = wResponse.GetResponseStream();
                StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8"));
                Return = reader.ReadToEnd();
                wResponse.Close();
                return Return;
            }
            catch (Exception e)
            {
                log.InfoFormat("网络异常：" + e.ToString());
                return null;
            }
          
        }
    }
}
